/*
 *
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: BaseListFreshFragment.java
 *   @Date: 1/24/19 7:47 PM
 *   @Author: chenjun
 *   @Description:
 *   @Copyright（C）: 2019 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 *
 */

package io.bhex.app.base;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

import io.bhex.app.R;
import io.bhex.app.account.presenter.CurrentEntrustFragmentPresenter;
import io.bhex.app.event.RevokeOrderEvent;
import io.bhex.app.trade.adapter.OpenOrdersAdapter;
import io.bhex.app.trade.presenter.BaseTradeFragmentPresenter;
import io.bhex.app.view.BookListView;
import io.bhex.app.view.StepView;
import io.bhex.baselib.utils.PixelUtils;
import io.bhex.sdk.trade.bean.OrderBean;

public abstract class BaseListFreshFragment<P extends BaseListFreshPresenter<V>, V extends BaseListFreshPresenter.BaseListFreshUI> extends BaseFragment<P, V> implements BaseListFreshPresenter.BaseListFreshUI,BaseQuickAdapter.RequestLoadMoreListener, OnRefreshListener {
    protected RecyclerView recyclerView;
    protected BaseQuickAdapter adapter;
    protected SmartRefreshLayout swipeRefresh;
    protected View emptyView;

    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.base_list_layout, null, false);
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onStop() {
        super.onStop();
    }


    @Override
    protected void initViews() {
        super.initViews();
        swipeRefresh = viewFinder.find(R.id.swipeRefresh);
        swipeRefresh.setOnRefreshListener(this);
        recyclerView = viewFinder.find(R.id.recyclerView);

        LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
        emptyView = layoutInflater.inflate(R.layout.empty_layout, swipeRefresh, false);
        ViewGroup.LayoutParams layoutParams = emptyView.getLayoutParams();
        layoutParams.height = PixelUtils.dp2px(200);
        emptyView.setLayoutParams(layoutParams);

    }

    @Override
    protected void addEvent() {
        super.addEvent();

    }

    @Override
    public void onLoadMoreRequested() {
        getPresenter().loadMore();
    }

    @Override
    public void loadMoreComplete() {
        if (adapter != null) {
            adapter.loadMoreComplete();
        }
    }

    @Override
    public void loadMoreFailed() {
        if (adapter != null) {
            adapter.loadMoreFail();
        }
    }

    @Override
    public void loadEnd() {
        if (adapter != null) {
            adapter.loadMoreEnd();
        }
    }

    @Override
    public void onRefresh(RefreshLayout refreshLayout) {
        getPresenter().getData(false);
        refreshLayout.finishRefresh(1000);
    }


}

